home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amos / amossible / structures / subrout.amos / subrout.amosSourceCode
Encoding:
AMOS Source Code  |  1980-05-17  |  1.5 KB  |  32 lines

  1. '*********************Err...I can't think of a Title.....********************* 
  2. Rem Although the loops we have shown are very useful and often essential,you 
  3. Rem can't always rely on them in more complex programs.For a more detailed 
  4. Rem explanation of subroutines,look at the on disk document files. 
  5. Rem Where would you need to use a subroutine?Well,imagine that in a game you 
  6. Rem had made,you had a main program loop,and had some `special things for the
  7. Rem computer to do when the player had won-But you couldn't include these in 
  8. Rem the main bit because you only want them to occur at certain points.
  9. Rem In this simple program,we start in the MAIN subroutine-It prints some
  10. Rem text,waits for point 30 of a second and then goes to the subroutine
  11. Rem SUBBIT(That is where the "Gosub" command comes from-the words GO to a  
  12. Rem SUBroutine)-This prints some text,waits for point ten of a second and  
  13. Rem goes back to where the program left off with the "Return" command- 
  14. Rem which puts us at the line "Gosub MAIN",so we go to the start of the MAIN 
  15. Rem subroutine and start again.
  16. Rem When you use the Gosub command you write:  
  17. Rem Gosub  
  18. Rem And then the name of the subroutine you want to goto(Here we use MAIN):
  19. Rem Gosub MAIN 
  20. Rem The start of a subroutine is signalled by its name and a colon after it: 
  21. Rem MAIN:
  22. Rem don't put anything after the colon,you have to start on the next line  
  23. Rem down.
  24. MAIN:
  25. Print "The Main routine!"
  26. Wait 30
  27. Gosub SUBBIT
  28. Gosub MAIN
  29. SUBBIT:
  30. Print "The subroutine"
  31. Wait 10
  32. Return